package logic

import (
	"context"
	"srv/sesame"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type EsSyncGoodsLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewEsSyncGoodsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *EsSyncGoodsLogic {
	return &EsSyncGoodsLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *EsSyncGoodsLogic) EsSyncGoods(req *types.EsSyncGoodsRequest) (resp *types.Response, err error) {
	_, err = l.svcCtx.SesameSrv.EsSyncGoods(l.ctx, &sesame.EsSyncGoodsRequest{})
	if err != nil {
		return &types.Response{
			Code: 500,
			Msg:  "同步商品到es失败",
		}, err
	}

	return &types.Response{
		Code: 200,
		Msg:  "同步商品到es成功",
	}, err
}
